package com.wxd.https.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author wxd
 * @version V1.0
 * @description ServerConfig
 * @date 2022/4/15 9:52
 **/
@Component
@Slf4j
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {

    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        try {
            InetAddress inetAddress = Inet4Address.getLocalHost();
            // 主机ip地址
            String hostAddress = inetAddress.getHostAddress();
            // tomcat启动端口
            int serverPort = event.getWebServer().getPort();
            log.info("项目启动成功！访问地址: https://{}:{}/{}", hostAddress, serverPort, "swagger-ui/index.html");
        } catch (UnknownHostException e) {
            log.error(e.getMessage(), e);
        }
    }

}